package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.UserService.UserShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端购物车接口")
public class ShoppingCartController {
    @Resource
    UserShoppingCartService ushopping;

    @PostMapping("add")
    @ApiOperation("添加购物车")
    public Result addShopping(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        int i = ushopping.ShoppingCartadd(shoppingCartDTO);
        return Result.success(i);
    }

    @GetMapping("list")
    @ApiOperation("查看购物车")
    public Result list() {
        List<ShoppingCart> shoppingCarts = ushopping.selectShoppingCart();
        return Result.success(shoppingCarts);
    }
    @DeleteMapping("clean")
    @ApiOperation("清空购物车商品")
    public Result clean(){
        ushopping.deleteShoppingCart();
        return Result.success();
    }
}
